home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 18 / CU Amiga Magazine's Super CD-ROM 18 (1997)(EMAP Images)(GB)[!][issue 1998-01].iso / CUCD / Online / CNetDemo / cnet / sdk / Examples / WaitForC.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-09-04  |  2.6 KB  |  119 lines

  1. /************************************************************************/
  2. /*                               WaitForC.c                             */
  3. /*             pause until the users presses the required key           */
  4. /************************************************************************/
  5.  
  6. #define SCALE 32768.0
  7. /* #include <time.h> */
  8. #include <math.h>
  9. #include <ctype.h>
  10.  
  11. void        CallHost( UBYTE c );
  12. void        ShutDown( char *spwan );
  13. void        GetOut( void );
  14. void        LoadError( void );
  15. BOOL        CarrierCheck( void );
  16.  
  17. struct    MsgPort  *replyp;                /* Some commnunication details ...      */
  18. struct    CPort    *cport;
  19. struct    CMessage  cmess;
  20. struct    MainPort  *myp;                /* Pointer to CNet port--ALL info!      */
  21. struct    PortData  *z;
  22. struct    SignalSemaphore *SEM;
  23.  
  24. float        randval;
  25.  
  26. unsigned    int    m;
  27.  
  28. char        **bm;
  29. char        key;
  30.  
  31. void main( int argc, char **argv )
  32. {
  33. char WaitKey;
  34.  
  35. if( argc<2 || !(cport = (struct CPort *)FindPort( argv[1] )) )
  36.     {
  37.     printf("Must be ran as a C-Net Pfile!\n");
  38.     exit(0);
  39.     }
  40. if( !(replyp = CreatePort( 0,0 ) ))
  41.     exit( 0 );
  42. cmess.cn_Message.mn_ReplyPort   = replyp;
  43. cmess.cn_Message.mn_Length      = sizeof( struct CMessage );
  44. cmess.cn_Message.mn_Node.ln_Name= "cstuff";
  45. if( cport->ack != 30 )
  46.     {    /* right CNet version running? */
  47.     cport->ack = 1;
  48.     LoadError();
  49.     }
  50. cport->ack = 0;
  51.  
  52. z        =    cport->zp;    /* this ports PortData */
  53. myp    =    cport->myp;    /* the system's MainPort */
  54. SEM    =    myp->SEM;    /* short hand if used often */
  55. bm        =    z->bm;
  56.  
  57.                        /* place your code here ! */
  58.  
  59. WaitKey = 'C';
  60. if(argc > 2)
  61.     {
  62.     WaitKey = toupper(argv[2][0]);
  63.     }
  64.  
  65. sprintf(z->ABuffer, "c4Press `%c' to continue..q1", WaitKey);
  66. PutText(z->ABuffer);
  67. while( (key=OneKey()) != WaitKey)
  68.     {
  69.     if(!CarrierCheck()) GetOut();
  70.     }
  71.     
  72. PutText("h9}h9}h5}");
  73. GetOut();
  74. }
  75.  
  76. void CallHost( UBYTE c )  /* Generic interface routine used by all below */
  77. {
  78.     cmess.command = c;
  79.     PutMsg  ( (struct MsgPort *)cport, (struct Message *)&cmess );
  80.     WaitPort( replyp );
  81.     GetMsg  ( replyp );
  82. }
  83.  
  84.     /* in your final code, you'll want to remove any of the following */
  85.     /* routines that you don't actually use to save some memory */
  86.  
  87. void PutText( char *text )
  88. {
  89.     cmess.arg1 = (ULONG)text;    /* text to print        */
  90.     CallHost( 1 );
  91. }
  92.  
  93. void GetOut( void )              /* exit pfile with no spawn */
  94. {
  95. CallHost( 0 );
  96. DeletePort( replyp );
  97. exit(0);
  98. }
  99.  
  100. void LoadError( void )
  101. {
  102. DeletePort( replyp );
  103. exit(0);
  104. }
  105.  
  106. char OneKey()                /* Stop until a key is pressed    */
  107. {
  108.     CallHost( 3 );
  109.     return( (char)cmess.result );
  110. }
  111.  
  112. BOOL CarrierCheck( void )
  113. {
  114. if( !z->Carrier ) return FALSE;
  115. if( !z->TimeLeft ) return FALSE;
  116. if( z->Dumped ) return FALSE;
  117. return TRUE;
  118. }
  119.